<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1" import="support.*, java.util.*, myclasses.*, java.io.*, java.sql.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Provide degrees - Choose discipline</title>
</head>
<body>
<%
	String uniIndex = request.getParameter("uniIndex");
	String university = request.getParameter("university");
	Degree currDeg = (Degree)session.getAttribute("currDegree");
	
	if(university != null && uniIndex == null) {
		try {
			Class.forName("org.postgresql.Driver");
		} catch(Exception e) {
			out.println("org.postgresql.Driver Exception. ");
		}
		try {
			String serverName = "localhost:5432";
		    String mydatabase = "ThirdBase";
		    String url = "jdbc:postgresql://" + serverName + "/" + mydatabase; 
		    String username = "SweetAss";
		    String password = "1234";
		    Connection conn = DriverManager.getConnection(url, username, password);
			Statement stmt = conn.createStatement();
			
			stmt.executeUpdate("INSERT INTO university (location,name) VALUES ('" + currDeg.getLocation() + "','" + university + "');");
			
			ResultSet indexRset = stmt.executeQuery("SELECT id FROM university WHERE name = '" + university + "';");
			indexRset.next();
			uniIndex = indexRset.getString(1);
			
			indexRset.close();
			conn.close();
			stmt.close();
		} catch(SQLException e) {
			e.printStackTrace();
			out.println("Connection exception.");
		}
	}

	currDeg.setUniversity(uniIndex);
%>
	
<center>
Please choose or add your discipline:

<form action="moreDegrees.jsp" method="get">
<p>
<%

	try {
		Class.forName("org.postgresql.Driver");
	} catch(Exception e) {
		out.println("org.postgresql.Driver Exception. ");
	}

	try {
		String serverName = "localhost:5432";
	    String mydatabase = "ThirdBase";
	    String url = "jdbc:postgresql://" + serverName + "/" + mydatabase; 
	    String username = "SweetAss";
	    String password = "1234";
	    Connection conn = DriverManager.getConnection(url, username, password);
		Statement stmt = conn.createStatement();
		
		ResultSet rset = stmt.executeQuery("SELECT id,name FROM major");
		while(rset.next()) {
			out.println("<input type=\"radio\" name=\"majorIndex\" value=\"" + rset.getString(1) + "\">" + rset.getString(2) + "</input>");

		}
		rset.close();
		stmt.close();
    	conn.close();
    
	} catch(SQLException e) {
		e.printStackTrace();
		out.println("Connection exception.");
	}
%>
	<br>
	Add: <input type ="text" size="40" name="major" />
	</p>


<p>
Graduation month: <input type ="text" size="7" name="month" />
 and year: <input type ="text" size="5" name="year" /></p>
 
<p>GPA: <input type ="text" size="7" name="gpa" /></p>

<p>Title: <select name="title" >
<option value="0">Select one</option>
<option value="1">BS</option>
<option value="2">MS</option>
<option value="3">PhD</option>
</select></p>

<input type="submit" value="Submit"/>
</form>
</center>

</body>
</html>